package pers.flowerinsnow.minecraft.forge.fastdungeonjoiner.listener

import net.minecraft.client.Minecraft
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import net.minecraftforge.fml.common.gameevent.InputEvent
import pers.flowerinsnow.minecraft.forge.fastdungeonjoiner.FastDungeonJoiner
import pers.flowerinsnow.minecraft.forge.fastdungeonjoiner.gui.MenuGui
import pers.flowerinsnow.minecraft.forge.fastdungeonjoiner.manager.{ConfigManager, KeyManager}
import pers.flowerinsnow.minecraft.forge.fastdungeonjoiner.util.{MessageUtils, StateUtils}

class KeyListener {
  @SubscribeEvent
  def onKeyInput(e: InputEvent.KeyInputEvent): Unit = {
    if (!StateUtils.isInSkyBlock) return
    if (KeyManager.FASTDUNGEON.isPressed) {
      val cmd = ConfigManager.Config.fastdungeon
      if (cmd.nonEmpty) {
        FastDungeonJoiner.addChatComponentMessage(ConfigManager.Messages.fastjoin_joining)
        Minecraft.getMinecraft.thePlayer.sendChatMessage("/" + cmd)
        return
      }
      FastDungeonJoiner.addChatComponentMessage(ConfigManager.Messages.fastjoin_notset
        .replace("*(KEY_BINDING)", KeyManager.OPENMENU.getKeyCode.toString))
      return
    }
    if (KeyManager.OPENMENU.isPressed) {
      MenuGui.create()
      return
    }
  }
}
